//
//  NetworkTool+compose.swift
//  JAWeiBo
//
//  Created by Arvin on 17/4/13.
//  Copyright © 2017年 Arvin. All rights reserved.
//

import UIKit

extension NetworkTool {
    /// 发布微博的接口的封装
    ///
    /// - Parameters:
    ///   - status: 微博正文
    ///   - imageData: 图片的二进制的数据
    ///   - callBack: 完成回调
    func updateStatus(status: String, imageData: Data?, callBack:@escaping (Any?)->()) {
        //带图片的微博
        if let imageData = imageData {
            
        let url = "https://upload.api.weibo.com/2/statuses/upload.json"
        let parameters = ["access_token": (JAUserAccount.shared.access_token)!,"status": status]
        
         //调用网络中间层的接口发布微博数据
            self.upload(url: url, parameters: parameters, data: imageData, name: "pic", fileName: "abc.png") { (response) in
                callBack(response)            }
        } else {
            //不带图片的微博
            let url = "https://api.weibo.com/2/statuses/update.json"
            let parameters = ["access_token": (JAUserAccount.shared.access_token)!,"status": status]
            
            //调用网络中间层的接口发布微博数据
            self.request(url: url
            , method: "POST", parameters: parameters) { (response) in
                callBack(response)
            }

        }
    
    }
    
}
